package com.bgy.model;

import java.util.List;

import com.jfinal.log.Log;
import com.jfinal.plugin.activerecord.ActiveRecordException;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;

public class Meetingcreate extends Model<Meetingcreate> {
	private static final long serialVersionUID = 6204222383226990020L;
	static Log log = Log.getLog(Meetingcreate.class);	
	public static final Meetingcreate me = new Meetingcreate();
	public boolean save(String name,String content,String starttime,
			String finishtime,String place,String zcr,String chr,String fqr,String fqrorg,
			String lxfs,String require){				
		Meetingcreate me = new Meetingcreate();
		me.set("name", name);
		me.set("content", content);
		me.set("starttime", starttime);	
		me.set("finishtime", finishtime);	
		me.set("place", place);	
		me.set("zcr", zcr);	  //
		me.set("chr", chr);	   //
		me.set("fqr", fqr);	
		me.set("lxfs", lxfs);	//
		me.set("require", require);
		me.set("issend", 0);
		me.set("status", 0);
		boolean result = false;
		try{
			result = me.save();			
		}catch(ActiveRecordException E){
			E.printStackTrace();
		}
		return result;
	}
	
	public List<Meetingcreate> getAll(String status){
		return me.find("select * from mms_meetingcreate where status=? order by xh desc",status);
	}
	
	public List<Meetingcreate> getAllSend(String sflag){
		return me.find("select * from mms_meetingcreate where issend=?",sflag);
	}
	
	public boolean setIsSend(int xh,int issend){
		int result = Db.update("update mms_meetingcreate set issend=? where xh=?", issend,xh);
		return result == 1?true:false;
	}
	/**
	 * 通过序号获取一条记录的详细信息
	 */	
	public Meetingcreate findByXh(String xh){		
		return this.findFirst("select * from mms_meetingcreate where xh=?", xh);
	}
	
	public List<Meetingcreate> getAllBusy(){
		return me.find("select xh,place,starttime,finishtime from mms_meetingcreate where starttime<=NOW() and finishtime>=NOW()");
	}
	
	/**
	 * 得到会议室状态，主持人，其实是发起人列表
	 * @return
	 */
	public List<Meetingcreate> getFqr(String xh){
		return me.find("select * from mms_meetingcreate where finishtime>NOW() and place in(select name from mms_meetingroom where xh=?)", xh);		
	}
	
	public void setStatus(){
		Db.update("update mms_meetingcreate set status=1 where NOW()>finishtime and status=0");
	}
	
	public int cancelMeeting(String xh,String status){
		int v = Db.update("update mms_meetingcreate set status=? where xh=?",status,xh);
		return v;
	}
}
